package io.renren.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.renren.common.service.impl.CrudServiceImpl;
import io.renren.dao.ProjectmDao;
import io.renren.dto.ProjectmDTO;
import io.renren.entity.GoodsmEntity;
import io.renren.entity.ProjectmEntity;
import io.renren.service.ProjectmService;
import cn.hutool.core.util.StrUtil;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * ${comments}
 *
 * @author Sen 524227263@qq.com
 * @since 1.0.0 2024-05-30
 */
@Service
public class ProjectmServiceImpl extends CrudServiceImpl<ProjectmDao, ProjectmEntity, ProjectmDTO> implements ProjectmService {

    @Override
    public QueryWrapper<ProjectmEntity> getWrapper(Map<String, Object> params) {
        String id = (String) params.get("id");

        QueryWrapper<ProjectmEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(StrUtil.isNotBlank(id), "id", id);

        return wrapper;
    }


    @Override
    public ProjectmEntity findOneByProjectMOID(String projectmFk) {
        QueryWrapper<ProjectmEntity> wrapper = new QueryWrapper<>();
        wrapper.eq("ProjectMOID", projectmFk);
        List<ProjectmEntity> list = this.baseDao.selectList(wrapper);
        return list.size() > 0 ? list.get(0) : null;
    }

    @Override
    public String findNameForInsuranceOID(String insuranceFk) {
        return this.baseDao.findNameForInsuranceOID(insuranceFk);
    }

    @Override
    public String findNameByProjectMOID(String projectMFk) {
        QueryWrapper<ProjectmEntity> wrapper = new QueryWrapper<>();
        wrapper.in("ProjectMOID", projectMFk);
        List<ProjectmEntity> list = this.baseDao.selectList(wrapper);
        return list.stream().map(ProjectmEntity::getName).reduce((a, b) -> a + "," + b).get();
    }

    @Override
    public List<Map<String, Object>> findListByAutoRepairMFK(String fk) {
        return this.baseDao.findListByAutoRepairMFK(fk);
    }
}